package com.xiaoyang.ssyx.common.exception;

import com.xiaoyang.ssyx.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @AUTHOR XiaoYang
 * @DATE 2023/6/13-16:04
 * @DESCRIPTION TODO 全局异常处理器
 */
//AOP
@ControllerAdvice
public class GlobalExceptionHandler {

    //当你出现异常执行
    @ExceptionHandler(Exception.class) //异常处理器
    @ResponseBody //返回JSON数据
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail(null);
    }

    //自定义异常处理
    @ExceptionHandler(SsyxException.class)
    @ResponseBody
    public Result error(SsyxException e){
        return Result.build(null,e.getCode(),e.getMessage());
    }

}
